using System;
using System.Collections.Generic;
using System.Text;
using Rapier.Kodachi.Shared;
using System.Windows.Forms;
//using System.Windows.Forms.Integration;
using System.Runtime.InteropServices;
using System.Drawing;

namespace Rapier.Kodachi.Core
{
    public class CoreNotifier : INotifier
    {
        //private ToastForm toastForm;
        private NotifyForm notifyForm = new NotifyForm();

        public CoreNotifier()
        {
            notifyForm.SetBackgroundBitmap(Resource.ToastBackground, Color.Magenta);
            notifyForm.ReShowOnMouseOver = true;

            notifyForm.TitleRectangle = new Rectangle(60, 5, 200, 25);
            notifyForm.ContentRectangle = new Rectangle(60, 30, 200, 125);
            notifyForm.ImageRectangle = new Rectangle(5, 5, 48, 48);
            notifyForm.NormalTitleFont = new Font("Tahoma", 10, FontStyle.Bold);
            notifyForm.HoverTitleFont = new Font("Tahoma", 10, FontStyle.Bold);
            notifyForm.NormalTitleColor = Color.White;
            notifyForm.HoverTitleColor = Color.LightSteelBlue;
            notifyForm.NormalContentColor = Color.White;
            notifyForm.HoverContentColor = Color.LightSteelBlue;
            notifyForm.NormalContentFont = new Font("Tahoma", 8, FontStyle.Regular);
            notifyForm.HoverContentFont = new Font("Tahoma", 8, FontStyle.Regular);
            notifyForm.EnableSelectionRectangle = false;
            notifyForm.TitleClickable = false;
            notifyForm.ContentClickable = false;
        }

        #region INotifier Members
        public void Notify(NotificationPackage package)
        {
            //if (toastForm != null && toastForm.Visible == true)
            //{
            //    toastForm.SetPackage(package);
            //}
            //else
            //{
            //    toastForm = new ToastForm(package);
            //    toastForm.Popup();
            //    //toastForm.Show();
            //}

            notifyForm.Show(package.Caption, package.Message, package.Image, 1000, 5000, 1000);
            if (package.IsCaptionClickable)
            {
               notifyForm.TitleClickable = true;
               notifyForm.ClearTitleClickHandlers();
               notifyForm.TitleClick += delegate(object sender, EventArgs e) { package.OnCaptionClick(); };
            }
            else
            {
               notifyForm.TitleClickable = false;
               notifyForm.ClearTitleClickHandlers();
            }
            if (package.IsMessageClickable)
            {
               notifyForm.ContentClickable = true;
               notifyForm.ClearContentClickHandlers();
               notifyForm.ContentClick += delegate(object sender, EventArgs e) { package.OnMessageClick(); };
            }
            else
            {
               notifyForm.ContentClickable = false;
               notifyForm.ClearContentClickHandlers();
            }
        }
        #endregion
    }
}
